package com.itany.hotel.service.proxy;

import com.itany.hotel.entity.Category;
import com.itany.hotel.entity.Room;
import com.itany.hotel.service.RoomService;
import framework.bean.factory.ObjectFactory;
import framework.dao.exception.DataAccessException;
import framework.service.exception.ServiceException;
import framework.service.transaction.TransactionManager;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class RoomServiceProxy implements RoomService {

    private RoomService roomService;

    public RoomServiceProxy() {
        roomService= (RoomService) ObjectFactory.getObject("roomServiceTarget");
    }

    @Override
    public List<Category> findCategories() {
        TransactionManager transactionManager= (TransactionManager) ObjectFactory.getObject("transaction");

        List<Category> categories=null;

        try {
            transactionManager.begin();

            categories=roomService.findCategories();

            transactionManager.commit();
        } catch (DataAccessException e){
            transactionManager.rollback();
            throw new ServiceException(e);
        }

        return categories;
    }

    @Override
    public List<Room> findAvailable(Integer categoryId, Integer resideType, Date startDate, Date endDate) {
        return null;
    }
}
